<?php
/*=============================================================================
#     FileName: PhotoController.class.php
#   LastChange: 2017-10-26 16:10:38
=============================================================================*/
namespace Admin\Controller;
use Vendor\UploadFile;

class PhotoController extends ComController
{
    public function index()
    {
        $this->display();
    }

    public function viewer(){
        $ids = I('ids');
        //dump($ids);

        $m = M('upload_img');
        $map['id'] = array('in', $ids);
        $cache = $m->where($map)->select();
        $this->assign('cache', $cache);
        $this->ajaxReturn($this->fetch());
    }

    public function upload(){
        $files = $_FILES;
        $act = I('get.act','','trim');

        if (empty($act)) {
            return $this->ajaxReturn(array('code'=>0,'msg'=>'没有act'));
        }

        if (empty($files)) {
            return $this->ajaxReturn(array('code'=>0,'msg'=>'没有上传文件'));
        }

        $up = new uploadFile($files,$act,'',2000,0,1,2);
        $up->setSavename();
        $res = $up->run('file');

        if (!$res) {
            return $this->ajaxReturn(array('code'=>0,'msg'=>'上传失败'));
        }

        $info = $up->getInfo();

        $res = array('code'=>1,'url'=>'/uploads/'.$act.'/'.date('Y-m-d').'/'.$info[0]['saveName']);
        $this->ajaxReturn($res);
    }

    public function indeximg() {
        //查找带回字段
        $fbid = I('fbid');
        $isall = I('isall');
        $this->assign('fbid', $fbid);
        $this->assign('isall', $isall);
        $page = '1,8';
        $m = M('Upload_img');
        $cache = $m->page($page)->order('id desc')->select();
        $this->assign('cache', $cache);
        $this->ajaxReturn($this->fetch());
    }

}
